<?php
    include_once '../../../../controlador/php/conexion/Conexion.php';
    $con = new Conexion();
    
    $fecha1 = $_REQUEST['capass2'];
    $fecha2 = $_REQUEST['capass22'];
    
    $f1 = date('Y-m-d',strtotime($fecha1));
    $f2 = date('Y-m-d',strtotime($fecha2));
    
    $indi = "select case when ate_procede = 'ex' then 'Espontaneo' end as ate, atem.total
            from atenMaterna as atm
            outer apply(select COUNT(DISTINCT adnIngreso) as total 
                                    from atenMaterna 
                                    where ate_fecha between '".$f1."' and '".$f2."'and ate_procede = 'ex')as atem
            where ate_procede ='ex' 
            group by ate_procede,atem.total
            union
            select case when ate_procede = 're' then 'Remitida' end as ate,atem.total
            from atenMaterna as atm
            outer apply(select COUNT(DISTINCT adnIngreso) as total 
                                    from atenMaterna 
                                    where ate_fecha between '".$f1."' and '".$f2."'and ate_procede = 're')as atem
            where ate_procede ='re' 
            group by ate_procede,atem.total
            union
            select case when ate_procede = 'hi' then 'Hospitalizacion Interconsulta' end as ate,atem.total
            from atenMaterna as atm
            outer apply(select COUNT(DISTINCT adnIngreso) as total 
                                    from atenMaterna 
                                    where ate_fecha between '".$f1."' and '".$f2."'and ate_procede = 'hi')as atem
            where ate_procede ='hi' 
            group by ate_procede,atem.total
            union
            select case when ate_procede = 'ui' then 'Urgencias Interconsulta' end as ate,atem.total
            from atenMaterna as atm
            outer apply(select COUNT(DISTINCT adnIngreso) as total 
                                    from atenMaterna 
                                    where ate_fecha between '".$f1."' and '".$f2."'and ate_procede = 'ui')as atem
            where ate_procede ='ui' 
            group by ate_procede,atem.total



";
    $lsti = $con->query($indi);
    while($res = mssql_fetch_array($lsti)){
        $lst[] = $res;
    }
    $con->cerrarConexion();
    print_r(json_encode($lst));

?>
